package com.qiaofang.controller;

import com.qiaofang.common.response.CommonResponse;
import com.qiaofang.common.response.SuccessfulResponseFactory;
import com.qiaofang.dto.PremisesDTO;
import com.qiaofang.dto.SearchWxMsgFailureDTO;
import com.qiaofang.dto.WxMsgFailureDTO;
import com.qiaofang.request.GetWxMsgStatusRequest;
import com.qiaofang.request.ListWxMsgFailureRequest;
import com.qiaofang.request.PremisesRequest;
import com.qiaofang.request.UpdateWxMsgFailureRequest;
import com.qiaofang.response.GetWxMsgStatusResponse;
import com.qiaofang.response.ListPremisesResponse;
import com.qiaofang.response.ListWxMsgFailureResponse;
import com.qiaofang.service.WxMsgFailureService;
import com.qiaofang.vo.WxMsgStatusVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.text.ParseException;

/**
 * @author qi.liu
 * @date: 2021/1/12 13:45
 */
@RestController
@Api(tags = {"微信推送消息"})
@RequestMapping(value = "/wxMsgFailure", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public class WxMsgFailureController {

    @Autowired
    private WxMsgFailureService wxMsgFailureService;

    @PostMapping(value = "/updateWxMsgFailure")
    @ApiOperation(value = "修改微信推送消息记录")
    public CommonResponse updateWxMsgFailure(@RequestBody @Valid UpdateWxMsgFailureRequest request){
        WxMsgFailureDTO dto=new WxMsgFailureDTO();
        BeanUtils.copyProperties(request, dto);
        wxMsgFailureService.updateWxMsgFailure(dto);
        return SuccessfulResponseFactory.getSuccessResponse();
    }

    @PostMapping(value = "/listWxMsgFailure")
    @ApiOperation(value = "推送失败的消息列表")
    public ListWxMsgFailureResponse listWxMsgFailure(@RequestBody ListWxMsgFailureRequest request) throws ParseException {
        ListWxMsgFailureResponse response=new ListWxMsgFailureResponse();
        SearchWxMsgFailureDTO dto = new SearchWxMsgFailureDTO();
        BeanUtils.copyProperties(request, dto);
        response.setData(wxMsgFailureService.listWxMsgFailure(dto,request.getPage()));
        return response;
    }

    @PostMapping(value = "/getWxMsgStatus")
    @ApiOperation(value = "消息接收权限查询")
    public GetWxMsgStatusResponse getWxMsgStatus(@RequestBody @Valid GetWxMsgStatusRequest request){
        GetWxMsgStatusResponse response = new GetWxMsgStatusResponse();
        response.setData(wxMsgFailureService.getWxMsgStatus(request.getPartnerPremisesDTO()));
        return response;
    }
}
